/*
 * OrganizeView.java
 */
package organize;

import error.DgoogleException;
import file.LocalSharedFile;
import file.RemoteSharedFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;

import java.awt.Toolkit;
import java.awt.Image;
import java.io.*;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.BitSet;
import java.util.Calendar;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import peer.IPeerFactory;
import peer.PeerFactory;
import peer.IPeerClient;
import javax.swing.table.DefaultTableModel;


/**
 * The application's main frame.
 */
public class OrganizeView extends FrameView {

    private int LeftWidth = 230;
    private int TotalHeight = 523;
    private int Height1 = 300;
    private int Height2 = 220;
    private int RightWidth = 750;
    private int RightWidth1 = 510;
    private int RightWidth2 = 240;
    private int TopLeftX = 0;
    private int TopLeftY = 0;
    private int BottomLeftX = 0;
    private int BottomLeftY = 303;
    private int TopMiddleX = 230;
    private int TopMiddleY = 0;
    private int TopRightX = 740;
    private int TopRightY = 0;
    private int BottomRightX = 230;
    private int BottomRightY = 303;
    public static boolean IsLoggedIn = false;
    public File sfile;
    public int published_num;
    public int iiF,iiP;
    public JFrame frame;
    public static String GName=null;
    public static Boolean GStatus=false;
    public static int ind=0;
    public static IPeerFactory factory = new PeerFactory();
    public IPeerClient client = null;
    public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter out = new PrintWriter(System.out, true);
    public static String [][] searchResult=new String[100][5];

    private void showPanels(boolean _IsLogIn) {

        if (!_IsLogIn) {
            panelUser.setVisible(true);
            jPanel2.setVisible(true);
            jPanel8.setVisible(true);
            panelQuery.setVisible(false);
            panelStatus.setVisible(false);
            panelFtp.setVisible(false);
            panelPublish.setVisible(false);
            panelDownload.setVisible(false);
        } else {
            panelUser.setVisible(false);
            jPanel2.setVisible(false);
            jPanel8.setVisible(false);
            panelQuery.setVisible(true);
            panelStatus.setVisible(true);
            panelFtp.setVisible(true);
            panelPublish.setVisible(true);
            panelDownload.setVisible(true);
        }

    }

    public OrganizeView(SingleFrameApplication app) {
        super(app);

        initComponents();

        Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif");
        this.getFrame().setIconImage(icon);


        // jPanel1.setSize(1000, TotalHeight);//pLogin
        //  jPanel1.setLocation(TopLeftX, TopLeftY);
        mainPanel.add(panelUser, new org.netbeans.lib.awtextra.AbsoluteConstraints(TopLeftX, TopLeftY, LeftWidth, TotalHeight));
        //jPanel7.setSize(RightWidth, Height1); //pSearchResult
        // jPanel7.setLocation(TopMiddleX, TopMiddleY);
        mainPanel.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(TopMiddleX, TopMiddleY, RightWidth, Height1));
        //  jPanel8.setSize(RightWidth, Height2); //pDownloads
        //   jPanel8.setLocation(BottomRightX, BottomRightY);
        mainPanel.add(jPanel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(BottomRightX, BottomRightY, RightWidth, Height2));


        //   jPanel6.setSize(LeftWidth, Height1);//pSearch
        //  jPanel6.setLocation(TopLeftX, TopLeftY);
        mainPanel.add(panelQuery, new org.netbeans.lib.awtextra.AbsoluteConstraints(TopLeftX, TopLeftY, LeftWidth, Height1));
        //   jPanel3.setSize(LeftWidth, Height2);//pLoginInfo
        //    jPanel3.setLocation(BottomLeftX, BottomLeftY);
        mainPanel.add(panelStatus, new org.netbeans.lib.awtextra.AbsoluteConstraints(BottomLeftX, BottomLeftY, LeftWidth, Height2));
        //   jPanel9.setSize(RightWidth1, Height1); //pSearchResult2
        //   jPanel9.setLocation(TopMiddleX, TopMiddleY);
        mainPanel.add(panelFtp, new org.netbeans.lib.awtextra.AbsoluteConstraints(TopMiddleX, TopMiddleY, RightWidth1, Height1));
        //   jPanel5.setSize(RightWidth2, Height1); //pSharedFiles
        //    jPanel5.setLocation(TopRightX, TopRightY);
        mainPanel.add(panelPublish, new org.netbeans.lib.awtextra.AbsoluteConstraints(TopRightX, TopRightY, RightWidth2, Height1));
        //   jPanel4.setSize(RightWidth, Height2); //pDownloads
        //     jPanel4.setLocation(BottomRightX, BottomRightY);

        mainPanel.add(panelDownload, new org.netbeans.lib.awtextra.AbsoluteConstraints(BottomRightX, BottomRightY, RightWidth, Height2));



        showPanels(IsLoggedIn);

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });




    }

    @Action

        public static BitSet fromByteArray(byte[] bytes) {
            BitSet bits = new BitSet();
            for (int i=0; i<bytes.length*8; i++) {
                if ((bytes[bytes.length-i/8-1]&(1<<(i%8))) > 0) {
                    bits.set(i);
                }
            }
            return bits;
        }


    public static int[] fromString(String value) {

        int pointers[],counter=0;
        int pointer=0;
        pointers=new int [8192];
        for(int i=0;i<8192;i++)
        {
            pointers[i]=0;
        }
        value=value.substring(1);
        counter++;
        while(value.contains(", "))
        {
            pointer=value.indexOf(',');
            pointers[counter]=Integer.parseInt(value.substring(0, pointer));
            value=value.substring(pointer+2);
            counter++;
        }
        pointer=value.indexOf('}');
        pointers[counter]=Integer.parseInt(value.substring(0, pointer));
        pointers[0]=counter;
        return pointers;
    }


    public static BitSet BitSetFromIntArray(int[] value) {

        BitSet bits = new BitSet();
        for(int i=1;i<=value[0];i++)
        {
            bits.set(value[i]);
        }
        return bits;
    }

    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = OrganizeApp.getApplication().getMainFrame();
            aboutBox = new OrganizeAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        OrganizeApp.getApplication().show(aboutBox);
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        panelUser = new javax.swing.JPanel();
        txtServer = new javax.swing.JTextField();
        lableServer = new javax.swing.JLabel();
        tabUser = new javax.swing.JTabbedPane();
        panelLogin = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        txtLoginPasswd = new javax.swing.JPasswordField();
        txtLoginUserName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        btnLogin = new javax.swing.JButton();
        checkRemPwd = new javax.swing.JCheckBox();
        lableStatus = new javax.swing.JLabel();
        panelRegister = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtRegisterName = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtRegisterUserName = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtRegisterPassword = new javax.swing.JPasswordField();
        btnRegister = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        txtResetPwdUserName = new javax.swing.JTextField();
        btnResetPassword = new javax.swing.JButton();
        txtChangePwdUserName = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtChangePwdOld = new javax.swing.JPasswordField();
        jLabel15 = new javax.swing.JLabel();
        txtChangePwdNew = new javax.swing.JPasswordField();
        jLabel16 = new javax.swing.JLabel();
        btnChangePwd = new javax.swing.JButton();
        panelDownload = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        panelStatus = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        btnLogoff = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        panelPublish = new javax.swing.JPanel();
        btnSelectFile = new javax.swing.JButton();
        btnPublish = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tableSharedFiles = new javax.swing.JTable();
        panelQuery = new javax.swing.JPanel();
        txtQuery = new javax.swing.JTextField();
        btnQuery = new javax.swing.JButton();
        jPanel8 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        panelFtp = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane4 = new javax.swing.JScrollPane();
        tableQueryResult = new javax.swing.JTable();
        btnDownload = new javax.swing.JButton();
        btnNext = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setMaximumSize(new java.awt.Dimension(980, 800));
        mainPanel.setMinimumSize(new java.awt.Dimension(980, 0));
        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(980, 530));
        mainPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        panelUser.setName("pLogin"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(organize.OrganizeApp.class).getContext().getResourceMap(OrganizeView.class);
        txtServer.setText(resourceMap.getString("txtServer.text")); // NOI18N
        txtServer.setName("txtServer"); // NOI18N

        lableServer.setText(resourceMap.getString("lableServer.text")); // NOI18N
        lableServer.setAlignmentX(0.5F);
        lableServer.setName("lableServer"); // NOI18N

        tabUser.setName("tabUser"); // NOI18N
        tabUser.setPreferredSize(new java.awt.Dimension(230, 627));

        panelLogin.setName("panelLogin"); // NOI18N

        jButton2.setText(resourceMap.getString("btnCancel.text")); // NOI18N
        jButton2.setName("btnCancel"); // NOI18N
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        txtLoginPasswd.setText(resourceMap.getString("txtPass.text")); // NOI18N
        txtLoginPasswd.setName("txtPass"); // NOI18N

        txtLoginUserName.setText(resourceMap.getString("txtUserName.text")); // NOI18N
        txtLoginUserName.setName("txtUserName"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        btnLogin.setText(resourceMap.getString("btnLogin.text")); // NOI18N
        btnLogin.setName("btnLogin"); // NOI18N
        btnLogin.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnLoginMouseClicked(evt);
            }
        });

        checkRemPwd.setText(resourceMap.getString("chkRemember.text")); // NOI18N
        checkRemPwd.setName("chkRemember"); // NOI18N

        lableStatus.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lableStatus.setText(resourceMap.getString("lableStatus.text")); // NOI18N
        lableStatus.setName("lableStatus"); // NOI18N

        javax.swing.GroupLayout panelLoginLayout = new javax.swing.GroupLayout(panelLogin);
        panelLogin.setLayout(panelLoginLayout);
        panelLoginLayout.setHorizontalGroup(
            panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLoginLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lableStatus, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(checkRemPwd)
                    .addGroup(panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelLoginLayout.createSequentialGroup()
                            .addComponent(btnLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(txtLoginPasswd, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtLoginUserName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelLoginLayout.setVerticalGroup(
            panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLoginLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtLoginUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtLoginPasswd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(checkRemPwd)
                .addGap(18, 18, 18)
                .addGroup(panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnLogin)
                    .addComponent(jButton2))
                .addGap(18, 18, 18)
                .addComponent(lableStatus)
                .addContainerGap(279, Short.MAX_VALUE))
        );

        tabUser.addTab(resourceMap.getString("panelLogin.TabConstraints.tabTitle"), panelLogin); // NOI18N

        panelRegister.setMinimumSize(new java.awt.Dimension(840, 33));
        panelRegister.setName("panelRegister"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        txtRegisterName.setText(resourceMap.getString("txtRegisterName.text")); // NOI18N
        txtRegisterName.setName("txtRegisterName"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        txtRegisterUserName.setText(resourceMap.getString("txtRegisterUserName.text")); // NOI18N
        txtRegisterUserName.setName("txtRegisterUserName"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        txtEmail.setText(resourceMap.getString("txtEmail.text")); // NOI18N
        txtEmail.setName("txtEmail"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        txtRegisterPassword.setText(resourceMap.getString("txtRegisterPassword.text")); // NOI18N
        txtRegisterPassword.setName("txtRegisterPassword"); // NOI18N

        btnRegister.setText(resourceMap.getString("btnRegister.text")); // NOI18N
        btnRegister.setToolTipText(resourceMap.getString("btnRegister.toolTipText")); // NOI18N
        btnRegister.setName("btnRegister"); // NOI18N
        btnRegister.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnRegisterMouseClicked(evt);
            }
        });

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        txtResetPwdUserName.setText(resourceMap.getString("txtResetPwdUserName.text")); // NOI18N
        txtResetPwdUserName.setName("txtResetPwdUserName"); // NOI18N

        btnResetPassword.setText(resourceMap.getString("btnResetPassword.text")); // NOI18N
        btnResetPassword.setToolTipText(resourceMap.getString("btnResetPassword.toolTipText")); // NOI18N
        btnResetPassword.setName("btnResetPassword"); // NOI18N
        btnResetPassword.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnResetPasswdMouseClicked(evt);
            }
        });

        txtChangePwdUserName.setText(resourceMap.getString("txtChangePwdUserName.text")); // NOI18N
        txtChangePwdUserName.setName("txtChangePwdUserName"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        txtChangePwdOld.setText(resourceMap.getString("txtChangePwdOld.text")); // NOI18N
        txtChangePwdOld.setName("txtChangePwdOld"); // NOI18N

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        txtChangePwdNew.setText(resourceMap.getString("txtChangePwdNew.text")); // NOI18N
        txtChangePwdNew.setName("txtChangePwdNew"); // NOI18N

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        btnChangePwd.setText(resourceMap.getString("btnChangePwd.text")); // NOI18N
        btnChangePwd.setName("btnChangePwd"); // NOI18N
        btnChangePwd.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnChangePwdMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout panelRegisterLayout = new javax.swing.GroupLayout(panelRegister);
        panelRegister.setLayout(panelRegisterLayout);
        panelRegisterLayout.setHorizontalGroup(
            panelRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRegisterLayout.createSequentialGroup()
                .addGroup(panelRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel5))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtRegisterName, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel10))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtRegisterUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel11))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel12))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtRegisterPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnRegister, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel13))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtResetPwdUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnResetPassword))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel14))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtChangePwdUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel15))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtChangePwdOld, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel16))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtChangePwdNew, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))
                    .addGroup(panelRegisterLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnChangePwd)))
                .addContainerGap())
        );
        panelRegisterLayout.setVerticalGroup(
            panelRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRegisterLayout.createSequentialGroup()
                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtRegisterName, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtRegisterUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtRegisterPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnRegister, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtResetPwdUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnResetPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtChangePwdUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtChangePwdOld, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtChangePwdNew, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnChangePwd, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(41, 41, 41))
        );

        tabUser.addTab(resourceMap.getString("panelRegister.TabConstraints.tabTitle"), panelRegister); // NOI18N

        javax.swing.GroupLayout panelUserLayout = new javax.swing.GroupLayout(panelUser);
        panelUser.setLayout(panelUserLayout);
        panelUserLayout.setHorizontalGroup(
            panelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelUserLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tabUser, javax.swing.GroupLayout.PREFERRED_SIZE, 327, Short.MAX_VALUE)
                    .addGroup(panelUserLayout.createSequentialGroup()
                        .addComponent(lableServer)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtServer, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        panelUserLayout.setVerticalGroup(
            panelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelUserLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lableServer))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabUser, javax.swing.GroupLayout.PREFERRED_SIZE, 523, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(100, Short.MAX_VALUE))
        );

        mainPanel.add(panelUser, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, 660));

        panelDownload.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("pDownload2.border.title"))); // NOI18N
        panelDownload.setName("pDownload2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "File Name", "Pear", "Total Size", "Remaining Size", "Status"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout panelDownloadLayout = new javax.swing.GroupLayout(panelDownload);
        panelDownload.setLayout(panelDownloadLayout);
        panelDownloadLayout.setHorizontalGroup(
            panelDownloadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDownloadLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 715, Short.MAX_VALUE)
                .addContainerGap())
        );
        panelDownloadLayout.setVerticalGroup(
            panelDownloadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDownloadLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                .addContainerGap())
        );

        mainPanel.add(panelDownload, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        panelStatus.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("pLoginInfo.border.title"))); // NOI18N
        panelStatus.setName("pLoginInfo"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        btnLogoff.setText(resourceMap.getString("btnLogoff.text")); // NOI18N
        btnLogoff.setName("btnLogoff"); // NOI18N
        btnLogoff.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnLogoffMouseClicked(evt);
            }
        });

        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N

        jLabel20.setText(resourceMap.getString("jLabel20.text")); // NOI18N
        jLabel20.setName("jLabel20"); // NOI18N

        javax.swing.GroupLayout panelStatusLayout = new javax.swing.GroupLayout(panelStatus);
        panelStatus.setLayout(panelStatusLayout);
        panelStatusLayout.setHorizontalGroup(
            panelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelStatusLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelStatusLayout.createSequentialGroup()
                        .addGroup(panelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9))
                        .addGap(25, 25, 25)
                        .addGroup(panelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel20)
                            .addComponent(jLabel19)
                            .addComponent(jLabel18)
                            .addComponent(jLabel17))
                        .addContainerGap(163, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelStatusLayout.createSequentialGroup()
                        .addComponent(btnLogoff)
                        .addGap(80, 80, 80))))
        );
        panelStatusLayout.setVerticalGroup(
            panelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelStatusLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel17))
                .addGap(18, 18, 18)
                .addGroup(panelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel18))
                .addGap(18, 18, 18)
                .addGroup(panelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel19))
                .addGap(29, 29, 29)
                .addGroup(panelStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel20))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addComponent(btnLogoff)
                .addContainerGap())
        );

        jLabel6.getAccessibleContext().setAccessibleName(resourceMap.getString("jLabel6.AccessibleContext.accessibleName")); // NOI18N

        mainPanel.add(panelStatus, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        panelPublish.setBorder(javax.swing.BorderFactory.createTitledBorder("Shared Files"));
        panelPublish.setName("pSharedFile"); // NOI18N

        btnSelectFile.setText(resourceMap.getString("btnSelectFile.text")); // NOI18N
        btnSelectFile.setName("btnSelectFile"); // NOI18N
        btnSelectFile.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnSelectFileMouseClicked(evt);
            }
        });

        btnPublish.setText(resourceMap.getString("btnPublish.text")); // NOI18N
        btnPublish.setName("btnPublish"); // NOI18N
        btnPublish.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnPublishMouseClicked(evt);
            }
        });

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        tableSharedFiles.setAutoCreateRowSorter(true);
        tableSharedFiles.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "No.", "File", "Path"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableSharedFiles.setName("tableSharedFiles"); // NOI18N
        jScrollPane3.setViewportView(tableSharedFiles);
        tableSharedFiles.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("tableSharedFiles.columnModel.title0")); // NOI18N
        tableSharedFiles.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("tableSharedFiles.columnModel.title1")); // NOI18N
        tableSharedFiles.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("tableSharedFiles.columnModel.title2")); // NOI18N

        javax.swing.GroupLayout panelPublishLayout = new javax.swing.GroupLayout(panelPublish);
        panelPublish.setLayout(panelPublishLayout);
        panelPublishLayout.setHorizontalGroup(
            panelPublishLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPublishLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelPublishLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPublishLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(btnSelectFile)
                        .addGap(34, 34, 34)
                        .addComponent(btnPublish))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE))
                .addContainerGap())
        );
        panelPublishLayout.setVerticalGroup(
            panelPublishLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPublishLayout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelPublishLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSelectFile)
                    .addComponent(btnPublish))
                .addContainerGap())
        );

        mainPanel.add(panelPublish, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        panelQuery.setBorder(javax.swing.BorderFactory.createTitledBorder("Search"));
        panelQuery.setName("pSearch"); // NOI18N

        txtQuery.setText(resourceMap.getString("txtQuery.text")); // NOI18N
        txtQuery.setName("txtQuery"); // NOI18N

        btnQuery.setText(resourceMap.getString("btnQuery.text")); // NOI18N
        btnQuery.setName("btnQuery"); // NOI18N
        btnQuery.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnQueryMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout panelQueryLayout = new javax.swing.GroupLayout(panelQuery);
        panelQuery.setLayout(panelQueryLayout);
        panelQueryLayout.setHorizontalGroup(
            panelQueryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelQueryLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelQueryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtQuery, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
                    .addGroup(panelQueryLayout.createSequentialGroup()
                        .addGap(52, 52, 52)
                        .addComponent(btnQuery, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        panelQueryLayout.setVerticalGroup(
            panelQueryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelQueryLayout.createSequentialGroup()
                .addGap(100, 100, 100)
                .addComponent(txtQuery, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnQuery)
                .addContainerGap(112, Short.MAX_VALUE))
        );

        mainPanel.add(panelQuery, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("pDownload.border.title"))); // NOI18N
        jPanel8.setName("pDownload"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTextArea2.setColumns(20);
        jTextArea2.setEditable(false);
        jTextArea2.setRows(5);
        jTextArea2.setEnabled(false);
        jTextArea2.setName("jTextArea2"); // NOI18N
        jScrollPane2.setViewportView(jTextArea2);

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 714, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(11, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                .addContainerGap())
        );

        mainPanel.add(jPanel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        panelFtp.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("pSearchResults2.border.title"))); // NOI18N
        panelFtp.setName("pSearchResults2"); // NOI18N

        jTabbedPane1.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        tableQueryResult.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "File Name", "Digest", "IP Addess"
            }
        ));
        tableQueryResult.setName("tableQueryResult"); // NOI18N
        jScrollPane4.setViewportView(tableQueryResult);
        tableQueryResult.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("tableQueryResult.columnModel.title0")); // NOI18N
        tableQueryResult.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("tableQueryResult.columnModel.title1")); // NOI18N
        tableQueryResult.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("tableQueryResult.columnModel.title2")); // NOI18N

        jTabbedPane1.addTab(resourceMap.getString("jScrollPane4.TabConstraints.tabTitle"), jScrollPane4); // NOI18N

        btnDownload.setText(resourceMap.getString("btnDownload.text")); // NOI18N
        btnDownload.setName("btnDownload"); // NOI18N
        btnDownload.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnDownloadMouseClicked(evt);
            }
        });

        btnNext.setText(resourceMap.getString("btnNext.text")); // NOI18N
        btnNext.setName("btnNext"); // NOI18N

        javax.swing.GroupLayout panelFtpLayout = new javax.swing.GroupLayout(panelFtp);
        panelFtp.setLayout(panelFtpLayout);
        panelFtpLayout.setHorizontalGroup(
            panelFtpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFtpLayout.createSequentialGroup()
                .addGroup(panelFtpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelFtpLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE))
                    .addGroup(panelFtpLayout.createSequentialGroup()
                        .addGap(199, 199, 199)
                        .addComponent(btnDownload)
                        .addGap(54, 54, 54)
                        .addComponent(btnNext, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        panelFtpLayout.setVerticalGroup(
            panelFtpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFtpLayout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(panelFtpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnNext)
                    .addComponent(btnDownload))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        mainPanel.add(panelFtp, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jLabel1.setIcon(resourceMap.getIcon("jLabel1.icon")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(13, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        mainPanel.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(organize.OrganizeApp.class).getContext().getActionMap(OrganizeView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 821, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 991, Short.MAX_VALUE)
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void btnLoginMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnLoginMouseClicked


        String user_name = txtLoginUserName.getText();
        String password = txtLoginPasswd.getText();
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        GName=user_name;
        client = factory.makePeerClient(user_name, user_name, password, txtServer.getText() , bootstrap_port, "");

        mainPanel.setEnabled(false);

        try {
            client.login();
            out.println("Login Done");
            GStatus=true;
            lableStatus.setText("Login Successful");

            //Do not allow login twice
            panelLogin.setEnabled(false);
        } catch (Exception e) {
            out.printf("Login failed : %s\n", e);
            GStatus=false;
            client.close();
            client = null;
            lableStatus.setText("Login Failed");
        }

        // DO NOT CLOSE client here!!!! Ftp Server is running inside client 
        // after login success.

        mainPanel.setEnabled(true);
        
        if (GStatus)
        {
            IsLoggedIn=true;
            showPanels(IsLoggedIn);

            jLabel17.setText(txtLoginUserName.getText());
            jLabel18.setText(txtLoginUserName.getText());
            jLabel19.setText("Logged in Peer");
            jLabel20.setText( sdf.format(cal.getTime()));
        }

        if(!checkRemPwd.isSelected())
        {
            txtLoginUserName.setText("");
            txtLoginPasswd.setText("");
        }
        System.out.println(IsLoggedIn+"ahsan");
    }//GEN-LAST:event_btnLoginMouseClicked

    private short bootstrap_port = 6606;

    private void btnRegisterMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnRegisterMouseClicked
        mainPanel.setEnabled(false);
        if(client == null)
        {
            client = factory.makePeerClient(txtRegisterUserName.getText(),
                    txtRegisterName.getText(), txtRegisterPassword.getText() ,
                    txtServer.getText(), bootstrap_port, txtEmail.getText());
        }
        try {
            client.register();
        } catch (DgoogleException ex) {
            JOptionPane.showMessageDialog(this.mainPanel, ex.getMessage(), "Register Fail", JOptionPane.ERROR_MESSAGE);
            Logger.getLogger(OrganizeView.class.getName()).log(Level.SEVERE, null, ex);
        } finally
        {
            client.close();
            client = null;
        }
        tabUser.setSelectedIndex(0);
        mainPanel.setEnabled(true);
    }//GEN-LAST:event_btnRegisterMouseClicked

    private void btnLogoffMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnLogoffMouseClicked
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            if(this.client != null)
            {
                client.close();
                client = null;
            }

            panelLogin.setEnabled(true);
            lableStatus.setText("Login Required");

            //if(input.startsWith("O"))
            {
                IsLoggedIn=false;
                showPanels(IsLoggedIn);
            }
    }//GEN-LAST:event_btnLogoffMouseClicked

    private void btnSelectFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSelectFileMouseClicked
        iiF++;

        final JFileChooser fc = new JFileChooser();
        int returnVal = fc.showOpenDialog(panelPublish);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            sfile = fc.getSelectedFile();
            //This is where a real application would open the file.
            System.out.println("Opening: " + sfile.getName() + ".\n");
        } else {
            System.out.println("Open command cancelled by user.\n");

            return;
        }

        int table_index;

        if(published_num<10)
        {
            table_index=published_num+1;
            tableSharedFiles.setValueAt(table_index, published_num, 0);
            tableSharedFiles.setValueAt(sfile.getName(), published_num, 1);
            tableSharedFiles.setValueAt(sfile.getPath(), published_num, 2);
            published_num++;
        }
        else
        {
            //custom title, error icon
            JOptionPane.showMessageDialog(frame,"Sorry, only 10 files per peer are supported at the moment.","Publishing Error",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnSelectFileMouseClicked

    private void btnPublishMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnPublishMouseClicked
        int[] selected_rows = tableSharedFiles.getSelectedRows();
        int published_count = 0;
        for(int row_index : selected_rows)
        {
            String path = tableSharedFiles.getValueAt(row_index, 2).toString();
            
            try {
                client.publish(path);
                published_count ++;
            } catch (DgoogleException ex) {
                Logger.getLogger(OrganizeView.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(OrganizeView.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        String message = String.format("Publish done, %d files published", published_count);
        JOptionPane.showMessageDialog(this.mainPanel, message);
    }//GEN-LAST:event_btnPublishMouseClicked

    private List<RemoteSharedFile> query_result;
    
    private void btnQueryMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnQueryMouseClicked
        String query = txtQuery.getText();

        if(query.isEmpty())
            return;

        try {
            List<RemoteSharedFile> result = client.query(query);

            //Clear old query result
            this.query_result = null;
            tableQueryResult.removeAll();
            DefaultTableModel model = (DefaultTableModel)tableQueryResult.getModel();
            int r = model.getRowCount();
            for(int j = 0; j < r; j++)
            {
                //Delete every row that already added.
                model.removeRow(0);
            }
            int i = 0;
            for(RemoteSharedFile f : result)
            {
                model.addRow(new Object[] {f.name(), f.abstraction(), f.getIp()});
//                tableQueryResult.setValueAt(f.name(), i, 0);
//                tableQueryResult.setValueAt(f.abstraction(), i, 1);
//                tableQueryResult.setValueAt(f.getIp(), i, 2);
                i++;
            }

            String message = String.format("Query done, %d files found", result.size());
            JOptionPane.showMessageDialog(this.mainPanel, message);

            this.query_result = result;

        } catch (DgoogleException ex) {
            Logger.getLogger(OrganizeView.class.getName()).log(Level.SEVERE, null, ex);
        }


        }//GEN-LAST:event_btnQueryMouseClicked

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        // TODO add your handling code here:
        txtLoginUserName.setText("");
        txtLoginPasswd.setText("");
    }//GEN-LAST:event_jButton2MouseClicked

    private void btnDownloadMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnDownloadMouseClicked
        int[] selected_rows = tableQueryResult.getSelectedRows();

        if(selected_rows.length == 0)
        {
            JOptionPane.showMessageDialog(this.mainPanel, "You have to select at least one file to download");
        }

        if(this.query_result == null)
        {
            JOptionPane.showMessageDialog(this.mainPanel, "Sorry, no query result found");
        }
        
        for(int row_index : selected_rows)
        {
            RemoteSharedFile f = query_result.get(row_index);

            int choice = JOptionPane.showConfirmDialog(this.mainPanel, "Do you want to download " +  f.name(), "Donwload", JOptionPane.YES_NO_OPTION);

            if(choice == 0) //Yes
            {
                try {
                    InputStream input_stream = this.client.download(f);
                    BufferedOutputStream out_stream = new BufferedOutputStream(new FileOutputStream(f.name()));
                    //One byte by one byte, now as slow as you might think
                    int b = input_stream.read();
                    int length = 0;
                    while(-1 != b)
                    {
                        out_stream.write(b);
                        length += 1;
                        b = input_stream.read();
                    }

                    input_stream.close();
                    out_stream.close();
                    String msg = String.format("%s is downloaded to current directory, file size is %d bytes ", f.name(), length);
                    JOptionPane.showMessageDialog(this.mainPanel, msg);
                } catch (DgoogleException ex) {
                    JOptionPane.showMessageDialog(this.mainPanel, ex.toString(), "Dgoogle System Error", JOptionPane.WARNING_MESSAGE);
                    Logger.getLogger(OrganizeView.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    JOptionPane.showMessageDialog(this.mainPanel, ex.toString(), "Network Error", JOptionPane.WARNING_MESSAGE);
                    Logger.getLogger(OrganizeView.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_btnDownloadMouseClicked

    private void btnResetPasswdMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnResetPasswdMouseClicked
        mainPanel.setEnabled(false);
        if(client == null)
        {
            client = factory.makePeerClient(txtResetPwdUserName.getText(),
                    txtResetPwdUserName.getText(), txtRegisterPassword.getText() ,
                    txtServer.getText(), bootstrap_port, txtEmail.getText());
        }
        try {
            client.resetPassword();
        } catch (DgoogleException ex) {
            Logger.getLogger(OrganizeView.class.getName()).log(Level.SEVERE, null, ex);
        } finally
        {
            client.close();
            client = null;
        }
     
        mainPanel.setEnabled(true);
    }//GEN-LAST:event_btnResetPasswdMouseClicked

    private void btnChangePwdMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnChangePwdMouseClicked
         mainPanel.setEnabled(false);
        if(client == null)
        {
            client = factory.makePeerClient(txtChangePwdUserName.getText(),
                    txtChangePwdUserName.getText(), txtChangePwdOld.getText() ,
                    txtServer.getText(), bootstrap_port, txtEmail.getText());
        }
        try {
            client.changePassword(txtChangePwdNew.getText());
        } catch (DgoogleException ex) {
            Logger.getLogger(OrganizeView.class.getName()).log(Level.SEVERE, null, ex);
        } finally
        {
            client.close();
            client = null;
        }

        mainPanel.setEnabled(true);
    }//GEN-LAST:event_btnChangePwdMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChangePwd;
    private javax.swing.JButton btnDownload;
    private javax.swing.JButton btnLogin;
    private javax.swing.JButton btnLogoff;
    private javax.swing.JButton btnNext;
    private javax.swing.JButton btnPublish;
    private javax.swing.JButton btnQuery;
    private javax.swing.JButton btnRegister;
    private javax.swing.JButton btnResetPassword;
    private javax.swing.JButton btnSelectFile;
    private javax.swing.JCheckBox checkRemPwd;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JLabel lableServer;
    private javax.swing.JLabel lableStatus;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JPanel panelDownload;
    private javax.swing.JPanel panelFtp;
    private javax.swing.JPanel panelLogin;
    private javax.swing.JPanel panelPublish;
    private javax.swing.JPanel panelQuery;
    private javax.swing.JPanel panelRegister;
    private javax.swing.JPanel panelStatus;
    private javax.swing.JPanel panelUser;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTabbedPane tabUser;
    private javax.swing.JTable tableQueryResult;
    private javax.swing.JTable tableSharedFiles;
    private javax.swing.JPasswordField txtChangePwdNew;
    private javax.swing.JPasswordField txtChangePwdOld;
    private javax.swing.JTextField txtChangePwdUserName;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JPasswordField txtLoginPasswd;
    private javax.swing.JTextField txtLoginUserName;
    private javax.swing.JTextField txtQuery;
    private javax.swing.JTextField txtRegisterName;
    private javax.swing.JPasswordField txtRegisterPassword;
    private javax.swing.JTextField txtRegisterUserName;
    private javax.swing.JTextField txtResetPwdUserName;
    private javax.swing.JTextField txtServer;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
    }